package kg.aibek.projecteuler.p10;

import java.util.ArrayList;

public class Problem30 {
	public void solve() {
		int total = 0;
		for (int i = 10; i <= 354294; i++) {
			ArrayList<Integer> list = getDigits(i);
			int a = 0;
			for (int ii : list) {
				a += ii * ii * ii * ii * ii;
			}
			if (a == i)
				total += i;
		}
		System.out.println(total);
	}

	private ArrayList<Integer> getDigits(int number) {
		ArrayList<Integer> list = new ArrayList<Integer>();

		if (number >= 100000) {
			list.add(number / 100000);
			number = number % 100000;
		}
		if (number >= 10000) {
			list.add(number / 10000);
			number = number % 10000;
		}
		if (number >= 1000) {
			list.add(number / 1000);
			number = number % 1000;
		}
		if (number >= 100) {
			list.add(number / 100);
			number = number % 100;
		}
		if (number >= 10) {
			list.add(number / 10);
			number = number % 10;
		}
		list.add(number);

		return list;
	}

	public static void main(String[] args) {
		Problem30 p = new Problem30();
		p.solve();
	}
}
